package com.libc.yygh.common.aspect;


import com.libc.yygh.common.DateUtilbc;
import com.libc.yygh.common.LoggerUtil;
import com.libc.yygh.common.StringUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.time.temporal.ChronoUnit;

/**
 * *
 *
 * @version 1.0<br>
 * @qualiFild MyDoneTimeAspect.java<br>
 * @author：LiBencheng<br>
 * @date Created on 2021年7月29日<br>
 */
@Aspect
@Component
public class MyMonitorCtrlRunAsp
{
    @Around ("@annotation(monitorctr)")
    public Object around(ProceedingJoinPoint joinpoint, MonitorCtrlRuning monitorctr) throws Throwable
    {
        //当前的时间
        Instant starTime = Instant.now();
        // 这里获取到所有的参数值的数组
        Object[] args = joinpoint.getArgs();
        LoggerUtil.debugFormat(Boolean.TRUE, "开始调用{[%s]}的方法{[%s]},\r\n参数是：{[%s]}",
                               monitorctr.funEffect(), monitorctr.method(), StringUtil.toString(args));
        Object obj = joinpoint.proceed();
        LoggerUtil.debugFormat(Boolean.TRUE, "方法结束时间是：{[%s]}一共运行：{[%s ms]}",
                               DateUtilbc.currentDateTime(),
                               ChronoUnit.MILLIS.between(starTime, Instant.now()));
        return obj;
    }
}
